﻿Imports System.Collections

Public Class UserInterface 
    Public GameManager As GameManagerCollection
    Public TextureManager As TextureManager
    Public ViewPort As Viewport

    Public DebugOn As Boolean = False
    Public Width As Single
    Public Height As Single

    Public UIFPSCounter As UIFPSCounter
    Public UITimeRuler As UITimeRuler
    Public UICommands As New UICommands
    Public UICommandBox As UICommandBox
    Public UIPlayerStatBars As UIStatBars
    Public UITargetStatBars As UIStatBars

    Public Font As SpriteFont
    'Public Font As SpriteFont
    'Public Background As Texture2D
    '        Font = UserInterface.TextureManager.GetTexture("Default").Font
    '    Background = UserInterface.TextureManager.GetTexture("Pixel").Texture2D

    Public Sub New(ByVal Game As DanoQuest)
        GameManager = Game.GameManager
        TextureManager = Game.GameManager.TextureManager
        Font = TextureManager.GetTexture("Default").Font
        Width = Game.GraphicsDevice.Viewport.Width
        Height = Game.GraphicsDevice.Viewport.Height
        ViewPort = Game.GraphicsDevice.Viewport 'TODO: Remove this!
        UIFPSCounter = New UIFPSCounter(Me) With {.Enabled = True}
        UITimeRuler = New UITimeRuler(Me)
        UICommandBox = New UICommandBox(Me)
        UIPlayerStatBars = New UIStatBars(Me) With {.SetType = UIStatBars.BarType.Player}
        UITargetStatBars = New UIStatBars(Me) With {.SetType = UIStatBars.BarType.Target}
    End Sub

    Public Sub UITestSub(SpriteBatch As SpriteBatch)
        If DebugOn Then
            ' TESTING AREA
            Try
                Dim SpriteList As New ArrayList
                SpriteList = GameManager.SpriteManager.SpriteList
                Dim SpawnTimers As New ArrayList
                SpawnTimers = GameManager.SpawnManager.Spawns
                SpriteBatch.DrawString(Font, "Sprites alive: " & SpriteList.Count, New Vector2(240, 40), Color.Red)
                SpriteBatch.DrawString(Font, "Spawns waiting: " & SpawnTimers.Count, New Vector2(240, 260), Color.Red)
                Dim I As Integer = 0
                For Each Sprite As Sprite In SpriteList
                    SpriteBatch.DrawString(Font, Sprite.Stats.Name & " (" & Sprite.Stats.Level & ") ID:" & Sprite.Stats.SpawnLoc.ToString, New Vector2(240, (60 + (20 * I))), Color.Red)
                    I += 1
                Next 'ToDo: This still draws an error! Not threadsafe!
                I = 0
                For Each Spawn As SpawnManager.Spawn In SpawnTimers
                    SpriteBatch.DrawString(Font, Spawn.Sprite.Stats.Name & " (" & Spawn.Sprite.Stats.Level & ") ID:" & Spawn.Sprite.Stats.SpawnLoc.ToString, New Vector2(240, (280 + (20 * I))), Color.Red)
                    I += 1
                Next
                SpriteBatch.DrawString(Font, GameManager.Player.Location.ToString & " - Floor Angle: " & GameManager.Player.Angle, New Vector2(1, 400), Color.Red)
            Catch ex As Exception
                Debug.WriteLine("UI TEST Error!!!")
            Finally
            End Try
        End If
    End Sub

    Public Sub Update()
        If UIFPSCounter.Enabled Then
            UIFPSCounter.Update()
        End If
    End Sub

    Public Sub Draw(SpriteBatch As SpriteBatch)  'SpriteBatch.Begin(SpriteSortMode.Deferred, Nothing, Nothing, Nothing, Nothing, Nothing)
        UIPlayerStatBars.Draw(SpriteBatch, GameManager.SpriteManager.Player)
        UITargetStatBars.Draw(SpriteBatch, GameManager.SpriteManager.Player.Target)
        UICommandBox.Draw(SpriteBatch)
        UITimeRuler.Draw(SpriteBatch)
        If UIFPSCounter.Enabled Then
            UIFPSCounter.Draw(SpriteBatch)
        End If
        UITestSub(SpriteBatch)
    End Sub

End Class